package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.ActorDto;
import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.ActorService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xu-jiaHui on 2017/4/7.
 */
@Controller
@RequestMapping("/rds_actor")
public class ActorController {
    @Resource
    private ActorService actorService;

    @RequestMapping(value = "/getActor4Dt")
    @ResponseBody
    public DTResponseDto getActor4Dt(DTRequestDto dtRequestDto) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = actorService.getActor4Dt(dtRequestDto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/updateActorById")
    @ResponseBody
    public JsonMsgDto updateActorById(ActorDto actorDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(actorService.updateActorById(actorDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/addActor")
    @ResponseBody
    public JsonMsgDto addActor(ActorDto actorDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(actorService.addActor(actorDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteActorById")
    @ResponseBody
    public JsonMsgDto deleteActorById(Integer actorId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(actorService.deleteActorById(actorId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


}